package com.huangwei.socketchat.client;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class ClientSocketThread implements Runnable {
    private Socket socket;

    public ClientSocketThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        serverMessagesLintenner();
    }

    public void serverMessagesLintenner() {
        BufferedReader inputStream;
        while (!Thread.interrupted()) {
            try {
                inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf8"));
                System.out.println(inputStream.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
